home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_010 / iff / gio.h < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  115 lines

  1. #ifndef GIO_H
  2. #define GIO_H
  3. /*----------------------------------------------------------------------*
  4.  * GIO.H  defs for Generic I/O Speed Up Package.             01/06/86
  5.  * See GIOCall.C for an example of usage.
  6.  * Read not speeded-up yet.  Only one Write file buffered at a time.
  7.  * Note: The speed-up provided is ONLY significant for code such as IFF
  8.  * which does numerous small Writes and Seeks.
  9.  *----------------------------------------------------------------------*/
  10.  
  11. /* Use this file interface in place of ALL Open,Close,Read,Write,Seek DOS
  12.  * calls for an optional i/o speed-up via buffering.  You must use ONLY
  13.  * these G routines for a file that is being buffered; e.g., call GClose
  14.  * to Close the file, etc.
  15.  * It is harmless though not necessary to use G routines for a file that
  16.  * is not being buffered; e.g., GClose and Close are equivalent in that
  17.  * case.
  18.  * This Version only buffers one file at a time, and only for writing.
  19.  * If you call GWriteDeclare for a second file before the first file
  20.  * is GClosed, the first file becomes unbuffered.  This is harmless, no
  21.  * data is lost, the first file is simply no longer speeded-up.
  22.  */
  23.  
  24. /* Before compiling any modules that make G calls, or compiling gio.c,
  25.  * you must set the GIO_ACTIVE flag below.
  26.  *
  27.  * To omit the speed-up code,
  28.  *    #define GIO_ACTIVE 0
  29.  *
  30.  * To make the speed-up happen:
  31.  * 1. #define GIO_ACTIVE 1
  32.  * 2. link gio.o into your program
  33.  * 3. GWriteDeclare(file, buffer, size)
  34.  *    after f
  35. GOpening the file and before doing
  36.  *    any writing.
  37.  * 4. ONLY use GRead, GWrite, GSeek, GClose -- do not use the DOS i/o
  38.  *    routines directly.
  39.  */
  40. #define GIO_ACTIVE 1
  41.  
  42. #ifndef EXEC_TYPES_H
  43. #include "exec/types.h"
  44. #endif
  45.  
  46. #ifndef LIBRARIES_DOS_H
  47. #include "libraries/dos.h"
  48. #endif
  49.  
  50. #ifndef OFFSET_BEGINNING
  51. #define OFFSET_BEGINNING OFFSET_BEGINING
  52. #endif
  53.  
  54. #if GIO_ACTIVE
  55.  
  56. /* Present for completeness in the interface.
  57.  * "openmode" is either MODE_OLDFILE to read/write an existing file, or
  58.  * MODE_NEWFILE to write a new file.
  59.  * RETURNs a "file" pointer to a system-supplied structure that describes
  60.  * the open file.  This pointer is passed in to the other routines below.*/
  61. /* extern BPTR GOpen(char *, int openmode); */
  62.  
  63. /* NOTE: Flushes & Frees the write buffer.
  64.  * Returns -1 on error from Write.*/
  65. /* extern int GClose(BPTR file);  */
  66.  
  67. /* Read not speeded-up yet.
  68.  * GOpen the file, then do GReads to get successive chunks of data in
  69.  * the file.  Assumes the system can handle any number of bytes in each
  70.  * call, regardless of any block-structure of the device being read from.
  71.  * When done, GClose to free any system resources associated with an
  72.  * open file.*/
  73. /* extern int GRead(BPTR, BYTE *, int nBytes);  */
  74.  
  75. /* Writes out any data in write buffer for file.
  76.  * NOTE WHEN have Seeked into middle of buffer:
  77.  * GWriteFlush causes current position to be the end of the data written.
  78.  * -1 on error from Write.*/
  79. /* extern int GWriteFlush(BPTR file);  */
  80.  
  81. /* Sets up variables to describe a write buffer for the file.*/
  82. /* -1 on error from Write.*/
  83. /* extern int GWriteDeclare(BPTR, BYTE *, LONG); */
  84.  
  85. /* ANY PROGRAM WHICH USES "GWrite" MUST USE "GSeek" rather than "Seek"
  86.  * TO SEEK ON A FILE BEING WRITTEN WITH "GWrite".
  87.  * "Write" with Generic speed-up.
  88.  * -1 on error from Write.  else returns # bytes written to disk.
  89.  * Call GOpen, then do successive GWrites with GSeeks if required,
  90.  * then GClose when done.  (IFF does require GSeek.)*/
  91. /* extern int GWrite( BPTR, BYTE *, int nBytes); */
  92.  
  93. /* "Seek" with Generic speed-up, for a file being written with GWrite.*/
  94. /* Returns what Seek returns, which appears to be the position BEFORE
  95.  * seeking, though the documentation says it returns the NEW position.*/
  96. /* CURRENTLY RETURNS 0 WHEN SEEKING WITHIN THE BUFFER.*/
  97. /* Eventually, will support two independent files, one being read, the
  98.  * other being written.  Or could support even more.  Designed so is safe
  99.  * to call even for files which aren't being buffered.*/
  100. /* extern int GSeek(BPTR, BYTE *, int mode);     */
  101.  
  102. #else /* not GIO_ACTIVE */
  103.  
  104. #define GOpen(filename, openmode)           Open(filename, openmode)
  105. #define GClose(file)               Close(file)
  106. #define GRead(file, buffer, nBytes)       Read(file, buffer, nBytes)
  107. #define GWriteFlush(file)          (0)
  108. #define GWriteDeclare(file, buffer, nBytes) (0)
  109. #define GWrite(file, buffer, nBytes)       Write(file, buffer, nBytes)
  110. #define GSeek(file, position, mode)       Seek(file, position, mode)
  111.  
  112. #endif GIO_ACTIVE
  113.  
  114. #endif
  115.